package com.chance.cc.crawler.development.bootstrap.flightclub;

import com.alibaba.fastjson.JSON;
import com.chance.cc.crawler.core.CrawlerEnum;
import com.chance.cc.crawler.core.downloader.proxy.Proxy;
import com.chance.cc.crawler.core.filter.FilterUtils;
import com.chance.cc.crawler.core.record.CrawlerRecord;
import com.chance.cc.crawler.core.record.CrawlerRequestRecord;
import com.chance.cc.crawler.development.controller.DevCrawlerController;
import com.chance.cc.crawler.development.scripts.allfeild.AICCommonField;
import org.apache.commons.lang3.StringUtils;

import static com.chance.cc.crawler.core.CrawlerEnum.CrawlerRequestType.*;
import static com.chance.cc.crawler.core.CrawlerEnum.CrawlerRequestType.internalDownload;

public class FlightclubStart {
    private static final String domain = "flightclub";
    public static final String site = "shoes";

    private static Proxy proxy = new Proxy();

    static {
//        代理配置
        proxy.setHost("http-dyn.abuyun.com");
        proxy.setPort(9020);
        proxy.setUsername("HL89Q19E86E2987D");
        proxy.setPassword("71F33D94CE5F7BF2");
    }

    public static void main(String[] args) {

        CrawlerRequestRecord crawlerRequestRecord=autoAgeComment();

        CrawlerRequestRecord keywordRecord = CrawlerRequestRecord.builder()
                .startPageRequest("autohome_series_keyword",turnPageItem)
                .httpUrl("http://192.168.1.215:9599/v1/meta/pcauto/keys?site=carSeriesDistributor")
                .requestLabelTag(supportSource)
                .requestLabelTag(internalDownload)
                .build();

        DevCrawlerController devCrawlerController = DevCrawlerController.builder()
                .triggerInfo(domain, domain + "_trigger", System.currentTimeMillis(), domain + "_job")
                .crawlerRequestQueue(DevCrawlerController.devRequestQueue(domain))
                .consoleResultPipeline("kafka")
                .fileResultPipeline("kafka","D:\\chance_log\\flightclubKafka-8-3_1.log",false)
//                .crawlerThreadNum(10)
                .requestRecord(crawlerRequestRecord)
//                .supportRecord(keywordRecord)//加载关键字
                .build("com.chance.cc.crawler.development.scripts.flightclub");
        devCrawlerController.start();
    }

    //    汽车时代评论
    public static CrawlerRequestRecord autoAgeComment(){

        String url = "https://www.flightclub.cn/sneaker/search/nike/0";
        CrawlerRequestRecord crawlerRequestRecord = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPage)
                .domain(domain)
                .httpUrl(url)
                .recordKey(url)
                .releaseTime(System.currentTimeMillis())
//                .filter(CrawlerEnum.CrawlerRecordFilter.keyOrDateRange)
                .filter(CrawlerEnum.CrawlerRecordFilter.key)
                .addFilterInfo(FilterUtils.memoryFilterKeyInfo(domain))
//                .addFilterInfo(FilterUtils.dateRangeFilterInfo(24*7, null))
                .resultLabelTag(CrawlerEnum.CrawlerDataType.article)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.interaction)
                .proxy(proxy)
                .build();
        crawlerRequestRecord.tagsCreator().bizTags().addDomain(domain);
        crawlerRequestRecord.tagsCreator().bizTags().addSite(site);
        return crawlerRequestRecord;
    }
}
